package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;


import com.mall.commons.result.ResponseUtil;
import com.mall.commons.tool.utils.CookieUtil;
import com.mall.commons.tool.utils.JwtTokenUtils;
import com.mall.shopping.IDeleteGoodsInCartsService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.DeleteGoodsInCartsResponse;

import com.mall.user.intercepter.TokenIntercepter;
import io.swagger.models.auth.In;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author TL
 * @created Date:2020/12/20 Time:21:15
 **/
@RestController
@RequestMapping("shopping")
public class DeleteGoodsInCartsByselectedController {

    @Reference(timeout = 3000,check = false)
    IDeleteGoodsInCartsService IDeleteGoodsInCartsService;

    @DeleteMapping("carts/{uid}/{goodsId}")
    public ResponseData deleteGoodsInCarts(@PathVariable("uid") String uid, @PathVariable("goodsId") String goodsId, HttpServletRequest request){
        String userId = (String) request.getAttribute(TokenIntercepter.USER_INFO_KEY);
        DeleteGoodsInCartsResponse deleteGoodsInCartsResponse =
                IDeleteGoodsInCartsService.deleteGoodsInCarts(Integer.parseInt(uid), Integer.parseInt(goodsId),Integer.parseInt(userId));
        ResponseData responseData = new ResponseData();
        responseData.setCode(Integer.valueOf(deleteGoodsInCartsResponse.getCode()));
        if (responseData.getCode() == Integer.parseInt(ShoppingRetCode.SUCCESS.getCode())){
            responseData.setSuccess(true);
            responseData.setResult(deleteGoodsInCartsResponse.getMsg());
            responseData.setMessage("success");
            return responseData;
        }
        responseData.setSuccess(false);
        responseData.setResult(deleteGoodsInCartsResponse.getMsg());
        responseData.setMessage("failure");
        return responseData;
    }


}
